<?php

namespace app\xcxapi\controller\v1;

use app\common\controller\XcxController;
use app\xcxapi\service\CustomerService;

class Customer extends XcxController
{
    /**
     * 客户列表
     * User: wufeng
     * Date: 2019/5/15.
     */
    public function customerLists()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->customerLists($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 获取客户编辑信息
     * User: wufeng
     * Date: 2020/02/29.
     */
    public function customer()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->customer($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }
	
	
	 /**
     * 添加试听学员
     * User: chenben 
     * Date: 2020/04/03.
     */
    public function addAudition()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->addAudition($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }


	 /**
     * 储值
     * User: chenben
     * Date: 2020/03/31.
     */
    public function storedValue()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->storedValue($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 新增客户
     * User: wufeng
     * Date: 2019/5/28.
     */
    public function addCustomer()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->addCustomer($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 客户详情
     * User: wufeng
     * Date: 2019/5/27.
     */
    public function customerDetail()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->customerDetail($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 试听班级列表
     * User: wufeng
     * Date: 2019/6/3.
     */
    public function auditionClassList()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->auditionClassList($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 到访试听/到访上门
     * User: wufeng
     * Date: 2019/12/31.
     */
    public function visit()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->visit($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 签到
     * User: wufeng
     * Date: 2020/01/06.
     */
    public function signStatus()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->signStatus($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 到访
     * User: wufeng
     * Date: 2020/01/06.
     */
    public function visitStatus()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->visitStatus($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 跟进
     * User: wufeng
     * Date: 2020/01/04.
     */
    public function followUpLists()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->followUpLists($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 释放客户到公海
     * User: wufeng
     * Date: 2020/01/09.
     */
    public function releaseCustomer()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->releaseCustomer($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 将客户标记为无效
     * User: wufeng
     * Date: 2020/01/09.
     */
    public function invalid()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->invalid($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 将客户转为正式学员.
     *
     * @throws \think\exception\DbException
     */
    public function changeStudent()
    {
        if ($this->request->isAjax() && $this->request->isPost()) {
            $where['id'] = ['in', input('ids')];
            $info = '转为正式学员';
            $arr = explode(',', input('ids'));
            $res = $this->studentModel->save(['is_audition' => 2, 'course_consultant_type' => 1, 'course_consultant' => get_current_name(), 'user_id' => get_current_id()], $where);
            foreach ($arr as $id) {
                // 学员客户跟进沟通记录写入
                $student = StudentModel::get($id);
                CommonService::writeFollowUpLog($id, input('campus_id'), 1, get_current_name().' '.'将客户'.' '.$student['student_name'].' '.$info, 1, $student['follow_up']);
            }
            if (false === $res) {
                $this->error('操作失败', null, '', 2);
            }
            $this->success('操作成功', null, '', 1);
        }
        $ids = explode(',', input('ids'));
        $count = \count($ids);

        return $this->fetch('', [
            'ids' => input('ids'),
            'count' => $count,
            'type' => input('type'),
            'campus_id' => input('campus_id'),
        ]);
    }

    /**
     * 移除客户
     * User: wufeng
     * Date: 2020/01/09.
     */
    public function delete()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->delete($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }
	
	 /**
     * 签约类型
     * User: chenben
     * Date: 2020/03/38.
     */
    public function getContractType()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->getContractType($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }
	
	/**
     * 收款
     * User: chenben 
     * Date: 2020/04/04.
     */
    public function customerReceivables()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->customerReceivables($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }
	
	/**
     * 获取校区教务/学管师
     * User: chenben 
     * Date: 2020/04/04.
     */
    public function getByCampusEduUser()
    {
        if ($this->request->isPost()) {
			$params = $this->request->param();
            $list = (new CustomerService($this->type))->getByCampusEduUser($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

	 /**
     * 创建订单
     * User: chenben
     * Date: 2020/03/39.
     */
    public function createOrder()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->createOrder($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

    /**
     * 产品/班级
     * User: wufeng
     * Date: 2020/01/10.
     */
    public function productClass()
    {
        if ($this->request->isPost()) {
            $params = $this->request->param();
            $list = (new CustomerService($this->type))->productClass($params);
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

	/**
	 * 班型、物品类型
	 * User: wufeng
	 * Date: 2020/04/23
	 *
	 */
	public function classTypeGoodType()
	{
		if ($this->request->isPost()) {
			$list = (new CustomerService($this->type))->classTypeGoodType();
			if (1 !== $list['code']) {
				$this->fail($list);
			}
			$this->win($list);
		}
		$this->fail('ILLEGAL_REQUEST');
	}
    /**
     * 收款归属、支付方式
     * User: wufeng
     * Date: 2020/01/11.
     */
    public function receivablesPaymentMethod()
    {
        if ($this->request->isPost()) {
            $list = (new CustomerService($this->type))->receivablesPaymentMethod();
            if (1 !== $list['code']) {
                $this->fail($list);
            }
            $this->win($list);
        }
        $this->fail('ILLEGAL_REQUEST');
    }

	/**
	 * 获取试听课节列表
	 * User: wufeng
	 * Date: 2020/04/01
	 *
	 */
    public function achieveAuditionClassDayLists()
	{
		if ($this->request->isPost()) {
			$params = $this->request->param();
			$list = (new CustomerService($this->type))->achieveAuditionClassDayLists($params);
			if (1 !== $list['code']) {
				$this->fail($list);
			}
			$this->win($list);
		}
		$this->fail('ILLEGAL_REQUEST');
	}
}
